#include <stdio.h>
#include <stdlib.h>
#include <linux/videodev2.h>
#include "capture.h"

int main() {
    Capture *capture = malloc(sizeof(Capture));
    capture->dev = "/dev/video0";
    capture->width = 640;
    capture->height = 400;
    capture->pixelformat = V4L2_PIX_FMT_YUYV;
    int ret = capture_open(capture);
    if(ret < 0) {
        fprintf(stderr, "Capture fail, exit.\n");
        return -1;
    }
    ret = capture_start(capture);
    if(ret < 0) {
        fprintf(stderr, "Capture fail, exit.\n");
        return -1;
    }
    char *pic;
    pic = capture_shot(capture);
    FILE* fd = fopen("test.yuv", "w+");
    fwrite(pic, 1, capture->sizeimage, fd);
    fclose(fd);
    ret = capture_stop(capture);
    if(ret < 0) {
        fprintf(stderr, "Capture fail, exit.\n");
        return -1;
    }
    ret = capture_close(capture);
    if(ret < 0) {
        fprintf(stderr, "Capture fail, exit.\n");
        return -1;
    }
    free(capture);
    return 0;
}
